package com.tuu.security;
import com.tuu.pojo.SysUser;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;
import java.util.Collection;
@Data
@EqualsAndHashCode(callSuper = false) //不调用父类的equals方法
@Accessors(chain = true)
public class SecurityUserDetails extends SysUser implements UserDetails {
    private Collection<? extends GrantedAuthority> authorities;
    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return authorities;
    }
    public SecurityUserDetails(String uid, Collection<? extends GrantedAuthority> authorities){
        this.authorities = authorities;
        this.setUsername(uid);
        //String encode = new BCryptPasswordEncoder().encode("123456");
        //this.setPassword(encode);
        this.setAuthorities(authorities);
    }
    public SecurityUserDetails(String uid,boolean isSingle, boolean isAccountNonExpired,boolean isAccountLock,Collection<? extends GrantedAuthority> authorities){
        this.authorities = authorities;
        this.setUsername(uid);
        this.setAccountNonExpired(isAccountNonExpired);
        this.setSingle(isSingle);
        //String encode = new BCryptPasswordEncoder().encode("123456");
        //this.setPassword(encode);
        this.setAuthorities(authorities);
    }
    /**
     * 账户是否过期
     * @return
     */
    @Override
    public boolean isAccountNonExpired() {
        System.out.println("账户是否过期"+this.isAccountNonExpired());
        return this.isAccountNonExpired();
        //return true;
    }
    /**
     * 是否禁用
     * @return
     */
    @Override
    public boolean isAccountNonLocked() {
        return true;
    }
    /**
     * 密码是否过期
     * @return
     */
    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }
    /**
     * 是否启用
     * @return
     */
    @Override
    public boolean isEnabled() {
        return true;
    }
}